﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class admin_Column_Edit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AdminCs.CheckLoginState();
        if (!this.IsPostBack)
        {
            if (Request.QueryString["dl"] == "del")　//删除一级分类
            {
                Menu_d_del();
            }
            else if (Request.QueryString["zl"] == "del")　//删除二级分类
            {
                Menu_z_del();
            }

            else if (Request.QueryString["xg"] == "edit")　　//显示文本信息
            {
                Menu_update();
            }
         
        }
    }
    private void Menu_d()　//添加二级分类
    {
        string Menu_Lock;
        string Menu_T = TextBox1.Text.Trim();
        int Menu_L = 2;
        string dl = Request.QueryString["dl"];
        string ID = Request.QueryString["Coumu_ID"];
        if (this.CheckBox1.Checked)
        {
            Menu_Lock = "1";

        }
        else
        {

            Menu_Lock = "0";
        }
        if (dl != null && ID != null && Menu_T != "")
        {
            string sqlstr2 = "insert into PsClass(Menu_Name,Menu_Level,Menu_ParentLevel,Menu_Lock)values('" + Menu_T + "','" + Menu_L + "','" + ID + "','" + Menu_Lock + "')";
            Class1.ExecSql(sqlstr2);
            Response.Write("<script language=javascript>alert('添加成功！');window.location='PSO_Manage.aspx';</script>");
        }
        else
        {
            Response.Write("<script language=javascript>alert('错误提示，请输入正确的信息！');window.location='PSO_Manage.aspx';</script>");
        }
    }


    private void Menu_d_del()//删除一级分类
    {
        string ID = Request.QueryString["Coumu_ID"];
        string sql = "select count(*) from PsClass where Menu_ParentLevel=" + ID;
        int i = int.Parse(Class1.SelOne(sql));
        if (i == 0)
        {
            string del1 = "delete from PsClass where Menu_ID=" + ID + "";
            Class1.ExecSql(del1);
            Response.Write("<script language=javascript>alert('删除成功！');window.location='PSO_Manage.aspx';</script>");
        }
        else
        {
            Response.Write("<script language=javascript>alert('错误提示，先删除底下子栏目，然后再删大栏目！');window.location='PSO_Manage.aspx';</script>");
        }
    }
    private void Menu_z_del()//删除二级分类
    {
        string ID = Request.QueryString["Coumu_ID"];
        string sql = "select count(*) from PsClass where Menu_ParentLevel=" + ID;
        int i = int.Parse(Class1.SelOne(sql));
        if (i == 0)
        {
            string del1 = "delete from PsClass where Menu_ID=" + ID + "";
            Class1.ExecSql(del1);
            Response.Write("<script language=javascript>alert('删除成功！');window.location='PSO_Manage.aspx';</script>");
        }
        else
        {
            Response.Write("<script language=javascript>alert('错误提示，先删除底下子栏目，然后再删大栏目！');window.location='PSO_Manage.aspx';</script>");
        }
    }
   
    private void Menu_update()//显示文本分类
    {
        string ID = Request.QueryString["Coumu_ID"];
        DataTable dt = Class1.ExecSel("select * from PsClass where Menu_ID='" + ID + "'");
        TextBox1.Text = Convert.ToString(dt.Rows[0]["Menu_Name"]);
        if (dt.Rows[0]["Menu_Lock"].ToString() == "1")
        {
            CheckBox1.Checked = true;
        }
        else
        {
            CheckBox1.Checked = false;
        }
    }
    private void Menu_edit()//修改栏目
    {
        string ID = Request.QueryString["Coumu_ID"];
        string Menu_Lock;
        if (CheckBox1.Checked)
        {
            Menu_Lock = "1";

        }
        else
        {

            Menu_Lock = "0";
        }


        string sqlstr = "update PsClass set Menu_Name = '" + TextBox1.Text.Trim() + "',Menu_Lock = '" + Menu_Lock + "'  where Menu_ID=" + ID + "";
        Class1.ExecSql(sqlstr);
        Response.Write("<script language=javascript>alert('修改成功！');window.location='PSO_Manage.aspx';</script>");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["dl"] == "add")
        {
            Menu_d();
        }

        else if (Request.QueryString["xg"] == "edit")
        {
            Menu_edit();
        }
    }
}
